﻿using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Media;

namespace StockTools.Model
{
    public class StockInfoModel : BindableBase
    {
        private string exchangeName;
        private decimal latestPrice;
        private string latestPriceText;
        private string code;
        private string name;
        private Color latestPriceTextColor;
        private decimal openingPrice;

        /// <summary>
        /// 股票名称
        /// </summary>
        public string Name { get => name; set => SetProperty(ref name, value); }

        /// <summary>
        /// 股票代码
        /// </summary>
        public string Code
        {
            get => code;
            set
            {
                if (value == null) { value = String.Empty; }
                SetProperty(ref code, value);
            }
        }
        /// <summary>
        /// 证交所
        /// </summary>
        public string ExchangeName { get => exchangeName; set => SetProperty(ref exchangeName, value); }
        /// <summary>
        /// 最新价格
        /// </summary>
        public decimal LatestPrice
        {
            get => latestPrice;
            set => SetProperty(ref latestPrice, value);
        }
        /// <summary>
        /// 最新价格展示
        /// </summary>
        public string LatestPriceText { get => latestPriceText; set => SetProperty(ref latestPriceText, value); }
        /// <summary>
        /// 开盘价
        /// </summary>
        public decimal OpeningPrice
        {
            get => openingPrice; set
            {
                openingPrice = value;
                if (latestPrice - openingPrice > 0)
                {
                    LatestPriceTextColor = Brushes.Red.Color;
                }
                else if (latestPrice - openingPrice < 0)
                {
                    LatestPriceTextColor = Brushes.Green.Color;
                }
                else
                {
                    LatestPriceTextColor = Brushes.Black.Color;
                }
            }
        }
        /// <summary>
        /// 前景色
        /// </summary>
        public Color LatestPriceTextColor { get => latestPriceTextColor; set => SetProperty(ref latestPriceTextColor, value); }

        protected override void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            base.OnPropertyChanged(args);

            if (args.PropertyName == "Code")
            {
                var settingConfig = new SettingConfig();

                settingConfig.Save(this.Code, null, null);
            }
        }
    }
}